/*
 * @name: 充值记录
 * @Author: along
 * @Date: 2020-05-06
 */
<template>
    <div class="container rechargeRecord">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">用户搜索:</p>
                    <el-input
                        v-model="head.keyword"
                        placeholder="用户ID或手机号或姓名"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">开始时间:</p>
                    <el-date-picker
                        v-model="head.start_time"
                        type="datetime"
                        placeholder="选择日期时间"
                        size="small"
                        @change="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">结束时间:</p>
                    <el-date-picker
                        v-model="head.end_time"
                        type="datetime"
                        placeholder="选择日期时间"
                        size="small"
                        @change="getTableData(1)"
                    />
                </div>
            </div>
            <div class="header-right">
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        搜索
                    </el-button>
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="fnRest()"
                    >
                        重置
                    </el-button>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="rechargeRecord"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="true_name"
                label="用户姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="phone"
                label="手机号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="title"
                label="标题"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="money"
                label="金额"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="create_time"
                label="充值时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <div class="clearfix-wrap">
                <p class="padination-money">总充值金额:{{ moneyCount }}元</p>
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import {getDate} from '@/assets/js/utils';
export default {
    /**
     * @param   {Object}     head                       筛选字段
     * @param   {Object}     filterData                 排序
     * @param   {Object}     page                       分页
     * @param   {Array}      tableData                  数据列表
     * @param   {OBject}     authResult                 权限列表
     */
    mixins: [back],
    data () {
        return {
            moneyCount: '',
            head: {
                keyword: '',
                start_time: '',
                end_time: ''
            },
            filterData: {
                sort_field: 'asc',
                sorttype: 'desc'
            },
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {},
    computed: {},
    watch: {},
    mounted () {
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: 'APP充值记录'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },
    methods: {
        /**
         * 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/finance%5Cget_recharge_list', {
                page_id: page || this.page.now_page,
                keyword: this.head.keyword,
                start_time: this.head.start_time ? getDate(new Date(this.head.start_time)) : '',
                end_time: this.head.end_time > 0 ? (getDate(new Date(this.head.end_time)) + 86400) : '',
            }, resp => {
                if (resp.code == 1) {
                    // this.moneyCount = resp.data.stat.total_money;
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;

                    let moneyCount = 0;

                    this.tableData.map(item=>{
                        moneyCount += Number(item.money);
                    });

                    this.moneyCount = moneyCount.toFixed(2)*1;
                }
            });
        },

        /**
         * 重置
         */
        fnRest () {
            this.head = {
                keyword: '',
                start_time: '',
                end_time: ''
            };
            this.getTableData(1);
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        .padination-money {
            padding: 15px 0 15px 10px;
            color: #333333;
            font-weight: 500;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            box-sizing: border-box;
            .clearfix-wrap {
                display: flex;
                justify-content: space-between;
            }
            .el-pagination {
                padding-top: 10px;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
</style>
<style lang="less">
    .rechargeRecord{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
    }
</style>